load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
    name = "io_buildbuddy_buildbuddy_toolchain",
    sha256 = "48546946879b1fd2dcba327ba15776c822f2ce9a9ef1077be9bf3ecadcc1564a",
    strip_prefix = "buildbuddy-toolchain-b2f5e7e3b126c6d7cf243227147478c0959bfc95",
    urls = ["https://github.com/buildbuddy-io/buildbuddy-toolchain/archive/b2f5e7e3b126c6d7cf243227147478c0959bfc95.zip"],
)

load("@io_buildbuddy_buildbuddy_toolchain//:deps.bzl", "buildbuddy_deps")

buildbuddy_deps()

load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy")

buildbuddy(name = "buildbuddy_toolchain")

http_archive(
    name = "rules_pkg",
    sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
        "https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
    ],
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

http_archive(
    name = "bazel-erlang",
    strip_prefix = "bazel-erlang-main",
    urls = ["https://github.com/rabbitmq/bazel-erlang/archive/main.zip"],
)

load("@bazel-erlang//:bazel_erlang.bzl", "bazel_erlang_deps")

bazel_erlang_deps()

load("//:workspace_helpers.bzl", "rabbitmq_external_deps")

rabbitmq_external_deps(rabbitmq_workspace = "@")

load("//deps/amqp10_client:activemq.bzl", "activemq_archive")

activemq_archive()

ADD_PLUGINS_DIR_BUILD_FILE = """set -euo pipefail

cat << EOF > plugins/BUILD.bazel
load("@rules_pkg//:pkg.bzl", "pkg_zip")

pkg_zip(
    name = "inet_tcp_proxy_ez",
    package_dir = "inet_tcp_proxy/ebin",
    srcs = [
        "@inet_tcp_proxy//:bazel_erlang_lib",
    ],
    package_file_name = "inet_tcp_proxy.ez",
    visibility = ["//visibility:public"],
)

filegroup(
    name = "standard_plugins",
    srcs = glob(["*.ez"]),
    visibility = ["//visibility:public"],
)
EOF
"""

http_archive(
    name = "rabbitmq-server-generic-unix-3.8.22",
    build_file = "@//:BUILD.package_generic_unix",
    patch_cmds = [ADD_PLUGINS_DIR_BUILD_FILE],
    strip_prefix = "rabbitmq_server-3.8.22",
    urls = ["https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.22/rabbitmq-server-generic-unix-3.8.22.tar.xz"],
)
